
import { _decorator, Color, Component, Label, Node ,Sprite,SpriteFrame} from 'cc';
import { CHARACTOR_STATUS, LINEUP_TYPE } from './Enum';
const { ccclass, property } = _decorator;

export type CharactorData = {
    uid : number,
    heroId : number,
    curHp : number,
    maxHp : number,
    speed : number,
    curAtk : number,
    anger : number,
    def : number,
    avoid : number,
    critical : number,
    qualtity : number,
    vGift : number[],
    vSkill : number[],
    atkSkill : number,
    combat : number
}

@ccclass('CharactorCtrl')
export class CharactorCtrl extends Component {

    private _SPHealthBar: Sprite = null;
    private _SPPercent: Sprite = null;
    private _HarmValueText : Label = null;

    charactorData : CharactorData = null;

    inited : boolean = false;

    start () {
        if(!this.inited)
        {
            this.Init()
        }
    }

    Init(){
        var nodeHealthBar = this.node.getChildByName("HealtBar");

        this._SPHealthBar = nodeHealthBar.getComponent(Sprite);
        this._SPPercent = nodeHealthBar.getChildByName("Percent").getComponent(Sprite);
        this._HarmValueText = this.node.getChildByName("HarmValueText").getComponent(Label);
        this.inited = true;
    }

    setHarmValue(value : number){
        this._HarmValueText.node.active = true;
        if(value > 0){
            this._HarmValueText.color = Color.YELLOW
        }
        else{
            this._HarmValueText.color = Color.RED
        }
        this._HarmValueText.string = value.toString()
    }

    setHarmValueVisble(flag : boolean){
        this._HarmValueText.node.active = flag;
    }

    setBlood (nPercent: number) {
        if(!this.inited){
            this.Init()
        }
        console.log("percent: ",nPercent)
        this._SPPercent.fillRange = nPercent;
    }

    setBloodVisible (flag: boolean) {
        this._SPHealthBar.node.active = flag;
    }

    setBloodSpriteFrame (spriteFrame: SpriteFrame) {
        this._SPPercent.spriteFrame = spriteFrame;
    }

    setCharactorData(data : CharactorData){
        this.charactorData = data;
    }

    getMaxHp(){
        return this.charactorData.maxHp;
    }
}

